package May;

class animal {
    public int age;
    public String name;

    public animal (int age, String name) {
        this.age = age;
        this.name = name;
    }

    public void eat () {
        System.out.println (name + "吃");
    }


    @Override
    public String toString () {
        return "animal{" +
                "age=" + age +
                ", name='" + name + '\'' +
                '}';
    }
}


class dog extends animal {

    public dog (int age, String name) {
        super (age, name);
    }

    //java同一个包下面不能有两个相同的类
    public void eat () {
        System.out.println (name + "狗吃东西");
    }
}

class Bird extends animal {
    public Bird (int age, String name) {
        super (age, name);
    }

    void fly () {
        System.out.println (name + "正在飞");
    }
}


public class Learn_5_6 {
    public static void main (String[] args) {
        animal an = new Bird (10, "hong");
        //Bird bird = (Bird) an;
        //bird.fly ();

        //向下转型，但是不安全
        if (an instanceof Bird) {
            Bird bird = (Bird) an;
            bird.fly ();
        }
    }

    public static void main2 (String[] args) {
        //对父类的方法进行重写
        animal an = new dog (10, "张三");
        an.eat ();
    }

}
